#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
# @Author  : Tina Yu
# @Time    : 2021-4-17 19:48
import time

import yaml
from selenium import webdriver

from wechat_test.constants import URL


# 获取登录cookie，并存储到yaml文件中
def get_chrome_cookies(driver):
    #driver=webdriver.Chrome()
    driver.get(URL)
    cookies = driver.get_cookies()
    with open("data_cookie.yaml", "w", encoding="utf8") as f:
        yaml.dump(cookies, f)
    driver.quit()


# 读取cookies
def read_available_cookie(self, chrome_driver):
    with open("data_cookie.yaml", encoding="utf-8") as f:
        cookies = yaml.safe_load(f)
        for cookie in cookies:
            chrome_driver.add_cookie(cookie)
    return chrome_driver
